package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.Person;
import com.noahplat.person.service.PersonService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Set;

/**
 * @ClassName: PersonController
 * @Description: 人员controller
 * @Author 李景星
 * @Date 2021/3/5
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/person")
@Validated
public class PersonController {

    @Autowired
    private PersonService personService;

    /**
     * 注册账号时，初始化人员
     * @param userId
     * @return
     */
    @PostMapping("/initPerson")
    public Result initPerson(@NotNull(message = "用户ID不能为空 ") @Min(value = 1, message = "用户ID不合法") Long userId){
        return personService.initPerson(userId);
    }

    /**
     * 更新人员
     * @param person
     * @return
     */
    @PutMapping("/updatePerson")
    public Result updatePerson(@RequestBody Person person){
        return personService.updatePerson(person);
    }

    /**
     * 查询uid
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:PersonController:getUid')")
    @GetMapping("/getUid")
    public Result<List<Person>> getuid(Long[] pid){
        return personService.getUid(pid);
    }

    /**
     * 查询人员数量
     * @param acctid
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:PersonController:getPersonCount')")
    @GetMapping("/getPersonCount")
    public Result getPersonCount(@NotNull(message = "账套ID不能为空 ") @Min(value = 1, message = "账套ID不合法")Long acctid){
        return personService.getPersonCount(acctid);
    }

    /**
     * 根据账户ID更新人员所属账套
     * @param acctid
     * @param uid
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:PersonController:updateAcctidByUid')")
    @PutMapping("/updateAcctidByUid")
    public Result updateAcctidByUid(@NotNull(message = "账套ID不能为空 ") @Min(value = 1, message = "账套ID不合法")Long acctid, @NotNull(message = "用户ID不能为空 ") @Min(value = 1, message = "用户ID不合法")Long uid){
        return personService.updateAcctidByUid(acctid, uid);
    }
}
